import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
class LicensePic extends StatefulWidget {
  final File licenseImg;
  final Function getLicenseImg;

  const LicensePic({Key key, this.licenseImg, this.getLicenseImg}) : super(key: key);
  @override
  _LicensePicState createState() => _LicensePicState();
}

class _LicensePicState extends State<LicensePic> {
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          width: setWidth(165),
          height: setWidth(110),
          decoration: BoxDecoration(
              border:
              Border.all(color: Color(0xffF0F0F0), width: setWidth(0.5))),
          alignment: Alignment.center,
          child: GestureDetector(
            onTap: (){
              _galleryImage(0);
            },
            child: Container(
              width: setWidth(148),
              height: setWidth(97),
              child: widget.licenseImg == null
                  ? Image.asset("assets/images/license_img.png", fit: BoxFit.cover)
                  : Image.file(widget.licenseImg, fit: BoxFit.cover),
            ),
          ),
        ),
      ],
    );
  }

  //从相册选择图片
  _galleryImage(int index) async {
    await ImagePicker.pickImage(source: ImageSource.gallery).then((value){
      if(value != null){
        widget.getLicenseImg(value);
      }
    });
  }

}